#测试博客登陆界面
import time

from selenium.webdriver.common.by import By
from common.Utils import BlogDriver
class BlogLogin:
    url=""
    driver=""
    def __init__(self):
        self.url="http://8.137.19.140:9090/blog_login.html"
        self.driver=BlogDriver.driver
        self.driver.get(self.url)

    #成功登陆的测试用例
    def LoginSucTest(self):
        # 连续多次的send_keys会出现关键词拼接,而不是替换,若要替换,先要clear
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        
        self.driver.find_element(By.CSS_SELECTOR,"#username").send_keys("zhangsan")
        self.driver.find_element(By.CSS_SELECTOR,"#password").send_keys("123456")
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()
    #能够找到博客首页的用户昵称,则登录成功,否则登陆失败
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.left > div > h3")
    #返回到登陆界面
        self.driver.back()
    #异常登陆的测试用例
    def LoginFailTest(self):
    #连续多次的send_keys会出现关键词拼接,而不是替换,若要替换,先要clear
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()

        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("zhangsan")
    #错误的密码
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("1234")
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
    # #检查是否登陆失败,出现的是弹窗
        alert = self.driver.switch_to.alert
        alert.accept()


# login=BlogLogin()
# login.LoginSucTest()
# login.LoginFailTest()